package models

import "time"

// ConsumerSubscription 存储 Consumer 订阅的 Topic
type ConsumerSubscription struct {
	*GormModel             // 嵌入基础模型 (Id uint PK, CreatedAt, UpdatedAt, DeletedAt) - 使用自增 ID 作为主键
	ConsumerID   string    `gorm:"type:varchar(255);not null;uniqueIndex:idx_consumer_topic" json:"consumer_id"` // 外键字段，加入复合唯一索引
	TopicName    string    `gorm:"type:varchar(255);not null;uniqueIndex:idx_consumer_topic" json:"topic_name"`  // 外键字段，加入复合唯一索引
	SubscribedAt time.Time `json:"subscribed_at"`                                                                // 手动添加时间戳

	// --- 关联关系 ---
	// 移除有问题的 Consumer 关联
	// Consumer Consumer `gorm:"foreignKey:ConsumerID;references:ConsumerID;constraint:OnDelete:CASCADE"`
	Topic Topic `gorm:"foreignKey:TopicName;references:TopicName"`
}

// TableName 自定义表名
func (ConsumerSubscription) TableName() string {
	return "consumer_subscriptions"
}
